<?php
/**
 *
 *
 */
namespace Yz\modules\Admin;
class Controller_Default
    extends \Yz_Controller_Abstract
    implements \Yz_Controller_Interface
{


    /**
     *
     */
    public function go( \Yz_Router_Interface $router )
    {
        $this->checkValidUser();

        \Yz_Controller_Abstract::$isAdmin = true;

        $args = $router->getArguments();

        $path = '';
        if (0 === $args->count()) {
            // TODO fetch the default admin module from config
            $path = "tasklist";
        }
        return $router->route($path, $args);
    }



    protected function checkValidUser()
    {
        debug();
        $user = \Yz_User_Default::getInstance();
        if ($user->isAdmin()) {
            return 0;
        }
        if ($user->isAuthenticated()) {
            $ex = new \Yz_Access_Exception_Forbidden();
        } else {
            $ex = new \Yz_Access_Exception_Unauthenticated();
        }
        throw $ex->withArgs(array('area' => 'Admin'));
    }

}
